# "package" is the namespace where the module's functionality/data resides. 
# It dictates the name of the file if you want it to be "use"d.
# If more than one word, it constrains the location of the module.
#      

package FileManager::FileLister;


use base 'Exporter';

our @EXPORT = qw(ListFiles);


sub process_files {
   my $path = shift;
   print $path;
   opendir (DIR, $path)
        or die "Unable to open $path: $!";
    my @fileList = ();
    my @files =
        # Third: Prepend the full path
        map { $path . '/' . $_ }
        # Second: take out '.' and '..'
        grep { !/^\.{1,2}$/ }
        # First: get all files
        readdir (DIR);
        #
        #
	closedir(DIR);

	for(@files) {
        if( -d $_) {
              print "\n$_ is a directory";
              push @files, process_files ($_);
	}
	else
	{
                my @finalFile = grep {/\.cpp$|\.h$|\.c$/} $_;
		if (@finalFile ) {
		print "\n@finalFile is a new file.";
                push(@fileList,@finalFile); 
                $fileCounter = $fileCounter + 1;
		}
	}   
    }
print "\n\nCount of files is ",$fileCounter, "\n";
return @fileList;
}


sub ListFiles {
    my $target = shift;
    $target = 'world' unless defined $target;
    print "Listing files in directory-> $target";
    @filesList = process_files ($target);

#     return "Hello, $target!\n";
    return @filesList;
}


1;
